<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../head.jsp"%>
	<noscript>
		<div class="alert alert-block span10">
			<h4 class="alert-heading">Warning!</h4>
			<p>You need to have <a href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a> enabled to use this site.</p>
		</div>
	</noscript>
	<div id="content" class="span10"><!-- content starts -->
		<div class="alert alert-success">
			<strong><a href="${base }user_frontIndex">首页</a>&gt;&gt;<a href="${base }shop_myOrderList">我的订单</a>&gt;&gt;订单详情</strong>
		</div>
		<div class="alert alert-info">
			<button type="button" class="close" data-dismiss="alert">×</button>
			<strong>订单说明：</strong><span id="o_declare">This alert needs your attention, but it's not super important.</span>
		</div>
		<div class="row-fluid sortable">
			<div class="box span12">
				<div class="box-header well" data-original-title>
					<h2><i class="icon-user"></i>订单详细列表</h2>
					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
						<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<table class="table table-striped table-bordered bootstrap-datatable datatable">
						<tr>
						  	<th>商家名称</th>
						  	<th>选择&nbsp;<input type="checkbox" name="all_details" /></th>
						  	<th>名称</th>
						  	<th>单价（元）</th>
						  	<th>数量</th>
						  	<th>状态</th>
						  	<th>操作</th>
						</tr>
					  	<tbody id="detailList"></tbody>
					</table>
				</div><!-- box-content end -->
			</div><!-- box span12 end  -->
		</div><!-- row-fluid sortable end  -->
	</div>
	<script type="text/javascript">
	<!--
		$(function() {
			getOrderDetailList = function() {
				$("#detailList").html("");
				$.ajax({
					url : "${base}shop_getMyOrderDetailList/${shopId }",
					success : function(response) {
						var info = "";
						var len = response.detaillist.length;
						var cancel_html = "";
						$.each(response.detaillist, function(i, item) {
							if (i == 0) {
								$("#o_declare").html(item.ORDERDECLARE);
							}
						  	info += "<tr>";
						  	if (i == 0) {
						  		info += "<td rowspan='" + len + "'>"+ item.SHOPNAME +"</td>";
						  	}
						  	if (item.OD_STATUS == 1) {
						  		cancel_html = "<a href='javascript:_cancelOrder(\"" + item.DETAIL_ID + "\");'>取消</a>";
						  	} else {
						  		cancel_html = "<a href='javascript:_reOrder(\"" + item.DETAIL_ID + "\");'>重新预订</a>";
						  	}
							info += "<td><input type=\"checkbox\" name=\"_detail\" value=\"" + item.DETAIL_ID + "\" /></td>";
							info += "<td>" + item.NAME + "</td>";
							info += "<td>" + item.NEWPRICE + (item.ISDEAL == 1 ? "（优惠）" : "") + "</td>";
							info += "<td>" + item.AMOUNT + "&nbsp;(" + item.FOODUNIT + ")</td>";
							info += "<td>" + (item.OD_STATUS == 1 ? "正常" : "已取消") + "</td>";
							info += "<td>" + cancel_html + "&nbsp;&nbsp;<a href='javascript:_delOrder(\"" + item.DETAIL_ID + "\");'>删除</a></td>";
							info += "</tr>";
						});
						 $("#detailList").append(info);
					}
				});
			}
			getOrderDetailList();
		});
		
		function _cancelOrder(detail_id) {
			$.post("${base}shop_changeOrderDetailStatus/" + detail_id + ",3", 
					function(response) {
						if (response && response.success) {
							alert(response.msg);
							getOrderDetailList();
						} else {
							alert(response.msg);
						}
			}, "json");
		}
		
		function _delOrder(detail_id) {
			$.post("${base}shop_deleteOrderDetails/" + detail_id, 
					function(response) {
						if (response && response.success) {
							alert(response.msg);
							getOrderDetailList();
						} else {
							alert(response.msg);
						}
			}, "json");
		}
		
		function _reOrder(detail_id) {
			$.post("${base}shop_changeOrderDetailStatus/" + detail_id + ",1", 
					function(response) {
						if (response && response.success) {
							alert(response.msg);
							getOrderDetailList();
						} else {
							alert(response.msg);
						}
			}, "json");
		}
	//-->
	</script>
<%@ include file="../../bottom.jsp" %>